﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace eProject.Model
{
    public class Activity
    {
        public const int MaxPriority = 10;
        public const int MinPriority = 1;

        public event PeriodChangedEventHandler PeriodChanged;       

        public event PriorityChangedEventHandler PriorityChanged;

        public delegate void PeriodChangedEventHandler(Activity activity, Period oldValue, Period newValue);

        public delegate void PriorityChangedEventHandler(Activity activity);

        public Activity(Task task, Employee employee, Period period, int priority)
        {
            Task = task;
            Employee = employee;
            _period = period;
            _priority = priority;//TODO checking parameters
        }
      
        public Task Task{get; private set;}

        public  Employee Employee{ get; private set;}
        private Period _period;
        public Period Period 
        {
            get{return _period;}
            set
            {
                var oldValue = _period;
                _period = value;
                InvokePeriodChanged(oldValue,_period);
            }}

        private int _priority;
        public int Priority
        {
            get { return _priority;}
            set
            {
                if (value > MaxPriority || value < MinPriority)
                {
                    throw new ArgumentException("Value of Priority must be between " + MinPriority + " and " + MaxPriority);
                }
                _priority = value;  
                InvokePriorityChanged();
            }
        }
        
        //public void Shift(long days)
        //{
        //    throw new NotImplementedException();
        //}

        //public void Resize(long days)
        //{
        //    throw new NotImplementedException();
        //}
        
        private void InvokePeriodChanged(Period oldValue, Period newValue)
        {
            var changed = PeriodChanged;
            if (changed != null) changed(this, oldValue, newValue);
        }       

        private void InvokePriorityChanged()
        {                 
            var changed = PriorityChanged;
            if (changed != null) changed(this);           
        }
    }
}
